<?php

use function GuzzleHttp\json_decode;

/**
 * 自定义接口文件
 * @date: 2019年2月14日 下午2:07:17
 * @param: $GLOBALS
 * @return:
 * @author: 龚华尧
 */
class indexdiyController extends baseController
{

    //构造方法
    public function __construct()
    {
        $this->common = new Common();

//        // 写入日志
//        $logModel = new logModel();
//        $logModel->addlog($this->common->Requert("yonghu"), "小程序请求接口：" . $this->common->getUrl(), $this->common->getIP(), "小程序操作日志");


        //接口安全验证开始
        if (ACTION != "uploadfile" && ACTION != "getxunihaizilist") {
//           $this->apisafefilter();
        }

    }

    /**
     * 查询政策库列表
     * @date: 2019年6月13日 下午1:29:57
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getzhengcekulistAction()
    {
        //返回条数
        $number = $this->NumberFilter($this->common->Requert("number"));
        //当前页数
        $page = $this->NumberFilter($this->common->Requert("page"));
        //当前页数
        $orderby = $this->common->Requert("orderby");

        $zhengcekuM = new zhengcekuModule();
        $toutiaoList = $zhengcekuM->getzhengcekuList($page, $number, $orderby);
        returnSuccess($toutiaoList, "成功", $code = 0);
    }

    /**
     * 查询首页政策库列表
     * @date: 2019年6月13日 下午1:29:57
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getmyzhengcekulistAction()
    {
        //返回条数
        $number = $this->NumberFilter($this->common->Requert("number"));
        //当前页数
        $page = $this->NumberFilter($this->common->Requert("page"));
        //当前页数
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));

        $zhengcekuM = new zhengcekuModule();
        $dingyuejiluM = new dingyuejiluModule();
        $dingyuejiluArray = $dingyuejiluM->getdingyuelistByYonghu($yonghu);

        //拼接政策关键词
        $whereStr = "";
        foreach ($dingyuejiluArray as $k1 => $v1) {
            if ($whereStr == "") {
                $whereStr = " biaoqian like '%{$v1["name"]}%' ";
            } else {
                $whereStr = $whereStr . " or " . "biaoqian like '%{$v1["name"]}%' ";
            }
        }

        //拼接扶持方向类型
        $fuchifangxiangs = "";
        $parameterM = new parameterModel();
        foreach ($dingyuejiluArray as $k1 => $v1) {
            $parameterdata = $parameterM->where("classid = '376' and u1 = '{$v1["name"]}' ")->one();
            if (count($parameterdata) > 0) {
                if ($fuchifangxiangs == "") {
                    $fuchifangxiangs = $parameterdata["u2"];
                } else {
                    $fuchifangxiangs = $fuchifangxiangs . " , " . $parameterdata["u2"];
                }
            }

        }
        if ($fuchifangxiangs != "") {
            $whereStr = $whereStr . " fuchifangxiang in ({$fuchifangxiangs}) ";
        }

        //拼接通用条件
        if ($whereStr == "") {
            $whereStr = "  (DATE_FORMAT( now( ) , '%Y-%m-%d' ) >= DATE_FORMAT(fawenriqi, '%Y-%m-%d') and DATE_FORMAT( now( ) , '%Y-%m-%d' ) <= DATE_FORMAT(jiezhiriqi, '%Y-%m-%d') ) and status = 1";
        } else {
            $whereStr = "  ({$whereStr}) and (DATE_FORMAT( now( ) , '%Y-%m-%d' ) >= DATE_FORMAT(fawenriqi, '%Y-%m-%d') and DATE_FORMAT( now( ) , '%Y-%m-%d' ) <= DATE_FORMAT(jiezhiriqi, '%Y-%m-%d') ) and status = 1";
        }
        $zcList = $zhengcekuM->getMyzhengcekuList($page, $number, "", $whereStr);
        returnSuccess($zcList, "成功", $code = 0);

    }

    /**
     * 查询热搜词
     * @date: 2019年6月13日 下午3:18:26
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function gethotwordsAction()
    {
        //返回条数
        $number = $this->NumberFilter($this->common->Requert("number"));
        $number = $number == 0 ? 3 : $number;

        $zhengcekuM = new zhengcekuModule();
        $wordsList = $zhengcekuM->getHotWordsFromDingyuelanmu($number);
        if (count($wordsList) == 0) {
            $wordsList = $zhengcekuM->getHotWords($number);
        }

        returnSuccess($wordsList, "成功", $code = 0);

    }

    /**
     * 查询政策库条件
     * @date: 2019年6月13日 下午3:18:26
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getzhengcekufenleiAction()
    {

        $zhengcekuM = new zhengcekuModule();
        $fenleiList = $zhengcekuM->getfenlei();
        returnSuccess($fenleiList, "成功", $code = 0);

    }

    /**
     * 查询政策详细==>拆分后效果
     * @date: 2019年6月13日 下午6:15:57
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getzhengcekudetailAction()
    {
        $id = $this->NumberFilter($this->common->Requert("id"));
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));

        $zhengcekuM = new zhengcekuModule();
        $detail = $zhengcekuM->getzhengcekuDetail($id);
        //处理是否已收藏
        $rizhiM = new rizhiModule();
        if ($rizhiM->iszan($id, $yonghu, 1, "sl_zhengceku")) {
            $detail['isshoucang'] = true;
        } else {
            $detail['isshoucang'] = false;
        }
        //处理是否已点赞
        if ($rizhiM->iszan($id, $yonghu, 2, "sl_zhengceku")) {
            $detail['iszan'] = true;
        } else {
            $detail['iszan'] = false;
        }
        returnSuccess($detail, "成功", $code = 0);

    }

    /**
     * 查询相关政策
     * @date: 2019年6月13日 下午6:15:57
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getzhengcekurelationlistAction()
    {
        $id = $this->NumberFilter($this->common->Requert("id"));

        $zhengcekuM = new zhengcekuModule();
        $list = $zhengcekuM->getRelationListByid($id);

        returnSuccess($list, "成功", $code = 0);

    }

    /**
     * 查询政策详细==>原文
     * @date: 2019年6月13日 下午6:15:57
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getzhengcekuyuanwendetailAction()
    {

        $id = $this->NumberFilter($this->common->Requert("id"));
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));

        $zhengcekuM = new zhengcekuModule();
        $detail = $zhengcekuM->getzhengcekuMokuaihuaDetail($id);
        //处理是否已收藏
        $rizhiM = new rizhiModule();
        if ($rizhiM->iszan($id, $yonghu, 1, "sl_zhengceku")) {
            $detail['isshoucang'] = true;
        } else {
            $detail['isshoucang'] = false;
        }
        //处理是否已点赞
        if ($rizhiM->iszan($id, $yonghu, 2, "sl_zhengceku")) {
            $detail['iszan'] = true;
        } else {
            $detail['iszan'] = false;
        }

        returnSuccess($detail, "成功", $code = 0);

    }

    /**
     * 点击收藏和点赞
     * @date: 2019年6月13日 下午7:06:52
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function addzanAction()
    {
        $commonClass = $this->common;
        $rizhiM = new rizhiModule();
        $laiyuanbianhao = $commonClass->Requert("laiyuanbianhao");
        $yonghu = $commonClass->Requert("yonghu");
        $leixing = $commonClass->Requert("leixing");
        $laiyuan = $commonClass->Requert("laiyuan");

        if ($rizhiM->addzan($laiyuanbianhao, $yonghu, $leixing)) {

            returnSuccess("更新成功", "成功", $code = 0);

        } else {

            returnFail("更新失败");
        }

    }

    /**
     * 取消点赞和收藏
     * @date: 2019年2月14日 下午7:14:32
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function cancelzanAction()
    {
        $laiyuanbianhao = $this->NumberFilter($this->common->Requert("laiyuanbianhao"));
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));
        $leixing = $this->NumberFilter($this->common->Requert("leixing"));
        $laiyuan = $this->common->Requert("laiyuan");

        $rizhiM = new rizhiModule();
        if ($rizhiM->delzan($laiyuanbianhao, $yonghu, $leixing, $laiyuan)) {
            returnSuccess("已取消操作", "取消操作", $code = 0);
        } else {
            returnFail("操作失败");
        }

    }

    //个人中心 start
    /**
     * 查询全部订阅栏目
     * @date: 2019年6月14日 下午3:22:24
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getalldingyuelanmuAction()
    {
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));
        $guanjiancitongjiM = new guanjiancitongjiModule();
        $list = $guanjiancitongjiM->getalldingyuelanmuList($yonghu);
        returnSuccess($list, "成功", $code = 0);
    }

    /**
     * 查询用户订阅的栏目
     * @date: 2019年6月14日 下午3:29:58
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getyonghudingyuelanmuAction()
    {
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));
        $dingyuejiluM = new dingyuejiluModule();
        $list = $dingyuejiluM->getdingyuelistByYonghu($yonghu);
        returnSuccess($list, "成功", $code = 0);
    }

    /**
     * 添加企业信息
     * @date: 2019年6月14日 下午5:45:59
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function updateqiyeinfoAction()
    {
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));
        $jingyingxinxiJsonStr = $this->common->Requert("jingyingxinxijsonstr");
        $qiyeM = new qiyeModule();
        $qiyeM->insertOrupdataqiyeByYonghu($yonghu, $jingyingxinxiJsonStr);
        returnSuccess("操作成功");
    }

    /**
     * 查询企业信息
     * @date: 2019年6月16日 上午2:50:48
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getqiyeinfoAction()
    {
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));
        $qiyeM = new qiyeModule();
        $qiyedata = $qiyeM->getqiyeinfoByyonghu($yonghu);
        returnSuccess($qiyedata);
    }

    /**
     * 查询企业的选项参数
     * @date: 2019年6月16日 上午2:50:54
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getqiyeparametersAction()
    {
        $parameterM = new parameterModel();
        $data["chanyeleibie"] = $parameterM->getparameterArrayByclassid("426");
        returnSuccess($data);
    }

    /**
     * 查询收藏记录
     * @date: 2019年6月16日 上午3:17:16
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getshoucangjiluAction()
    {
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));
        $shoucangjia = $this->NumberFilter($this->common->Requert("shoucangjia"));
        $yonghuM = new yonghuModule();
        $list = $yonghuM->getshoucanglistByyonghuId($yonghu, $shoucangjia);
        returnSuccess($list);
    }

    /**
     *   查询地区
     * @date: 2019年7月8日 下午3:49:58
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getdiqulistAction()
    {
        $diquM = new diquModule();
        $list = $diquM->gettreelistByclassid("");
        returnSuccess($list);
    }
    //个人中心 end

    //政策动态  start
    /**
     * 查询政策动态热搜词
     * @date: 2019年6月13日 下午3:18:26
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getdongtaihotwordsAction()
    {
        //返回条数
        $number = $this->NumberFilter($this->common->Requert("number"));
        $number = $number == 0 ? 3 : $number;
        $zhengcedongtaiM = new zhengcedongtaiModule();
        $wordsList = $zhengcedongtaiM->getHotWords($number);
        returnSuccess($wordsList, "成功", $code = 0);

    }

    /**
     * 查询政策动态条件
     * @date: 2019年6月13日 下午3:18:26
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getzhengcedongtaifenleiAction()
    {
        $zhengcedongtaiM = new zhengcedongtaiModule();
        $fenleiList = $zhengcedongtaiM->getfenlei();
        returnSuccess($fenleiList, "成功", $code = 0);
    }

    /**
     * 查询政策动态列表
     * @date: 2019年6月13日 下午1:29:57
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getzhengcedongtailistAction()
    {
        //返回条数
        $number = $this->NumberFilter($this->common->Requert("number"));
        //当前页数
        $page = $this->NumberFilter($this->common->Requert("page"));
        $zhengcedongtaiM = new zhengcedongtaiModule();
        $toutiaoList = $zhengcedongtaiM->getzhengcekuList($page, $number);
        returnSuccess($toutiaoList, "成功", $code = 0);
    }

    /**
     * 查询政策动态详细
     * @date: 2019年6月13日 下午6:15:57
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getzhengcedongtaidetailAction()
    {
        $id = $this->NumberFilter($this->common->Requert("id"));
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));
        $zhengcedongtaiM = new zhengcedongtaiModule();
        $detail = $zhengcedongtaiM->getzhengcedongtaiDetail($id);
        //处理是否已收藏
        $rizhiM = new rizhiModule();
        if ($rizhiM->iszan($id, $yonghu, 1, "sl_zhengcedongtai")) {
            $detail['isshoucang'] = true;
        } else {
            $detail['isshoucang'] = false;
        }
        //处理是否已点赞
        if ($rizhiM->iszan($id, $yonghu, 2, "sl_zhengcedongtai")) {
            $detail['iszan'] = true;
        } else {
            $detail['iszan'] = false;
        }

        //查询相关动态
        $detail["xiangguanlist"] = $zhengcedongtaiM->getrelationdongtai($id, 1, 3);
        returnSuccess($detail, "成功", $code = 0);

    }
    //政策动态  end

    //政策解读 start
    /**
     * 查询政策解读热搜词
     * @date: 2019年6月13日 下午3:18:26
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getjieduhotwordsAction()
    {
        //返回条数
        $number = $this->NumberFilter($this->common->Requert("number"));
        $number = $number == 0 ? 3 : $number;
        $zhengcejieduM = new zhengcejieduModule();
        $wordsList = $zhengcejieduM->getHotWords($number);
        returnSuccess($wordsList, "成功", $code = 0);
    }

    /**
     * 查询政策动态条件
     * @date: 2019年6月13日 下午3:18:26
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getzhengcejiedufenleiAction()
    {
        $zhengcejieduM = new zhengcejieduModule();
        $fenleiList = $zhengcejieduM->getfenlei();
        returnSuccess($fenleiList, "成功", $code = 0);
    }

    /**
     * 查询政策库列表
     * @date: 2019年6月13日 下午1:29:57
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getzhengcejiedulistAction()
    {
        //返回条数
        $number = $this->NumberFilter($this->common->Requert("number"));
        //当前页数
        $page = $this->NumberFilter($this->common->Requert("page"));
        $zhengcejieduM = new zhengcejieduModule();
        $toutiaoList = $zhengcejieduM->getzhengcekuList($page, $number);
//        pr($toutiaoList);exit;
        returnSuccess($toutiaoList, "成功", $code = 0);

    }

    /**
     * 查询政策解读详细
     * @date: 2019年6月13日 下午6:15:57
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getzhengcejiedudetailAction()
    {
        $id = $this->NumberFilter($this->common->Requert("id"));
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));
        $zhengcejieduM = new zhengcejieduModule();
        $detail = $zhengcejieduM->getzhengcekuDetail($id);
        //处理是否已收藏
        $rizhiM = new rizhiModule();
        if ($rizhiM->iszan($id, $yonghu, 1, "sl_zhengcejiedu")) {
            $detail['isshoucang'] = true;
        } else {
            $detail['isshoucang'] = false;
        }
        //处理是否已点赞
        if ($rizhiM->iszan($id, $yonghu, 2, "sl_zhengcejiedu")) {
            $detail['iszan'] = true;
        } else {
            $detail['iszan'] = false;
        }
        //查询相关动态
        $detail["xiangguanlist"] = $zhengcejieduM->getrelationdongtai($id, 1, 3);

        returnSuccess($detail, "成功", $code = 0);

    }
    //政策解读 end


    //政策匹配 start
    /**
     * 查询企业列表
     * @date: 2019年6月17日 下午2:31:40
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getqiyelistAction()
    {
        //返回条数
        $number = $this->NumberFilter($this->common->Requert("number"));
        //当前页数
        $page = $this->NumberFilter($this->common->Requert("page"));
        $qiyemingcheng = $this->common->Requert("qiyemingcheng");
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));

        //查询数据
        $qiyekuM = new qiyekuModule();
        $list = $qiyekuM->getlistByqiyemingcheng($qiyemingcheng, $page, $number);
        returnSuccess($list, "成功", $code = 0);
    }

    /**
     * 查询匹配的问题
     * @date: 2019年6月18日 下午2:13:10
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getpipeiwentilistAction()
    {
        $timuM = new timuModule();
        $timulist = $timuM->getallList();
        returnSuccess($timulist, "成功", $code = 0);
    }

    /**
     * 查询选项对应问题
     * @date: 2019年6月18日 下午2:13:10
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getxiayitilistAction()
    {
        $xiayiti = $this->common->Requert("xiayiti");
        if (!$this->common->isEmpty($xiayiti)) {
            returnFail("xiayiti参数不能为空");
        }
        $timuM = new timuModule();
        $timulist = $timuM->getListByids($xiayiti);
        returnSuccess($timulist, "成功", $code = 0);
    }

    /**
     * 发送短信
     * @date: 2019年2月21日 下午3:05:35
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function sendsmsAction()
    {
        $shoujihao = $this->common->Requert("shoujihao");
        $this->library("Sms");
        $smsClass = new Sms();
        $yonghuM = new yonghuModule();
        //验证是否已经激活
        if ($yonghuM->isjihuo($shoujihao)) {
            returnFail("账号已激活，请联系管理员");
        } else {
            $smsClass->lingkai($shoujihao, "", "验证码");
            returnSuccess("短信已发送", "成功", $code = 0);
        }
    }

    /**
     * 提交匹配问题
     * @date: 2019年6月19日 下午4:13:15
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function submitpipeitimuAction()
    {
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));
        $qiye = $this->NumberFilter($this->common->Requert("qiye"));
        $daanJsonStr = $this->common->Requert("daanjsonstr");
        $daanJson = json_decode($daanJsonStr, true);
        $pipeijiluM = new pipeijiluModule();
        $curPipeiId = $pipeijiluM->insertone($yonghu, $qiye, $daanJson);
        returnSuccess(['pipeijiluid', $curPipeiId]);
    }

    /**
     * 添加搜查记录
     * @date: 2019年6月20日 下午3:42:23
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function insetsousuojiluAction()
    {
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));
        $qiye = $this->NumberFilter($this->common->Requert("qiye"));
        //添加公司的搜索记录
        $gongsisousuoM = new gongsisousuoModule();
        $gongsisousuodata["yonghu"] = $yonghu;
        $gongsisousuodata["qiye"] = $qiye;
        $gongsisousuoM->insertone($gongsisousuodata);
        returnSuccess("添加成功");
    }

    /**
     * 查询匹配结果详细
     * @date: 2019年6月19日 下午5:44:35
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getpipeixiangxiAction()
    {
        $id = $this->NumberFilter($this->common->Requert("id"));
        $pipeijiluM = new pipeijiluModule();
        $data = $pipeijiluM->getdetailByid($id);
        returnSuccess($data);
    }

    /**
     * 查询匹配记录列表
     * @date: 2019年6月21日 上午10:15:37
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getpipeijilulistAction()
    {
        $yonghu = $this->NumberFilter($this->common->Requert("yonghu"));
        $pipeijiluM = new pipeijiluModule();
        $relist = $pipeijiluM->getlistByyonghu($yonghu);
        returnSuccess($relist);

    }
    //政策匹配end

    /**
     * 预处理政策库文件
     * @date: 2019年6月21日 上午10:54:11
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function pretreatment_zhengcekuAction()
    {
        $id = $this->common->Requert("id");
        $c_type = $this->common->Requert("c_type");
        $zhengcekuM = new zhengcekuModule();
        //更新分类
//        $zhengcekuM->updateSortidByids($id);
        if ($c_type == 2){
            //模块化
            $zhengcekuM->updateMokuaihuaByids($id);
        }else{
            //更新关键词
            $zhengcekuM->updateguanjianciByids($id);
        }
        returnSuccess("更新成功");
    }

    /**
     * 预处理政策库文件的关键词
     * @date: 2019年6月21日 上午10:54:11
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function pretreatmentguanjianci_zhengcekuAction()
    {
        set_time_limit(0);
        $id = $this->common->Requert("id");
        $zhengcekuM = new zhengcekuModule();
        //更新关键词
        $zhengcekuM->updateguanjianciByids($id);
        returnSuccess("更新成功");
    }

    /**
     * 预处理政策库文件的分类
     * @date: 2019年6月21日 上午10:54:11
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function pretreatmentsortid_zhengcekuAction()
    {
        $id = $this->common->Requert("id");
        $zhengcekuM = new zhengcekuModule();
        //更新分类
        $zhengcekuM->updateSortidByids($id);
        returnSuccess("更新成功");
    }

    /**
     * 预处理政策库文件的拆分即模块化
     * @date: 2019年6月21日 上午10:54:11
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function pretreatmentmokuaihua_zhengcekuAction()
    {
        $id = $this->common->Requert("id");
        $zhengcekuM = new zhengcekuModule();
        //更新模块化
        $zhengcekuM->updateMokuaihuaByids($id);
        returnSuccess("更新成功");
    }

    /**
     * 政策库预处理四方平台的数据
     * @date: 2019年6月28日 上午4:27:03
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function pretreatmentsifangshuju_zhengcekuAction()
    {
        ini_set('max_execution_time', '0');
        $id = $this->common->Requert("id");
        $zhengcekuM = new zhengcekuModule();
        //更新模块化
        $zhengcekuM->TreatmentSifangshujuByids($id);
        returnSuccess("更新成功");
    }

    /**
     * 更新栏目
     * @date: 2019年7月8日 下午5:22:34
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function updatedingyuelanmuAction()
    {
        $guanjianciTongjiM = new guanjiancitongjiModule();
        $guanjianciTongjiM->importCiFromZhengceku();
        returnSuccess("更新成功");
    }

    /**
     * 设置为定于栏目
     * @date: 2019年7月9日 上午12:19:46
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function updateguanjiancitodingyuelanmuAction()
    {
        $id = $this->common->Requert("id");
        $guanjianciTongjiM = new guanjiancitongjiModule();
        $guanjianciTongjiM->updateleixingByids($id);
        returnSuccess("更新成功");
    }

    /**
     * Name:批量设为热搜词
     * Notes:
     * User: gonghuayao
     * Date: 2020-01-17
     * Time: 14:51
     */
    public function updateguanjiancitoresouAction()
    {
        $id = $this->common->Requert("id");
        $guanjianciTongjiM = new guanjiancitongjiModule();
        $guanjianciTongjiM->updateresouByids($id);
        returnSuccess("更新成功");
    }

    /**
     * 获取四方平台的政策动态
     * @date: 2019年9月2日 下午3:09:30
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getsifangzhengcedongtaiAction()
    {
        set_time_limit(0);
        $zhengcedongtaiM = new zhengcedongtaiModule();
        $page = $this->common->Get("page") == "" ? 1 : $this->common->Get("page");
        $getJsonStr = $this->common->get_webHtml("http://www.cdsme.com/xcxapi.aspx?type=getzhengcedongtai&page={$page}");
        $getJson = json_decode($getJsonStr, true);
        $iswhile = true;
        while ($iswhile) {
            var_dump("http://www.cdsme.com/xcxapi.aspx?type=getzhengcedongtai&page={$page}");
            flush();
            if (count($getJson) > 0) {
                $page = $page + 1;
                $iswhile = true;
            } else {
                $iswhile = false;
                break;
            }
            foreach ($getJson as $k => $v) {
                $zhengcedongtaiM->insertFromSifangdata($v);
            }
            $getJsonStr = $this->common->get_webHtml("http://www.cdsme.com/xcxapi.aspx?type=getzhengcedongtai&page={$page}");
            $getJson = json_decode($getJsonStr, true);
        }
        returnSuccess("导入完成");
    }

    /**
     * 获取四方平台的政策解读
     * @date: 2019年9月2日 下午3:09:30
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getsifangzhengcejieduAction()
    {
        set_time_limit(0);
        $zhengcejieduM = new zhengcejieduModule();
        $page = $this->common->Get("page") == "" ? 1 : $this->common->Get("page");
        $getJsonStr = $this->common->get_webHtml("http://www.cdsme.com/xcxapi.aspx?type=getzhengcejiedu&page={$page}");
        var_dump("http://www.cdsme.com/xcxapi.aspx?type=getzhengcejiedu&page={$page}");
        $getJson = json_decode($getJsonStr, true);
        $iswhile = true;
        while ($iswhile) {
            if (count($getJson) > 0) {
                $page = $page + 1;
                $iswhile = true;
            } else {
                $iswhile = false;
                break;
            }
            foreach ($getJson as $k => $v) {
                $zhengcejieduM->insertFromSifangdata($v);
            }
            $getJsonStr = $this->common->get_webHtml("http://www.cdsme.com/xcxapi.aspx?type=getzhengcejiedu&page={$page}");
            $getJson = json_decode($getJsonStr, true);
        }
        returnSuccess("导入完成");
    }

    /**
     * 获取四方平台的政策库
     * @date: 2019年9月2日 下午3:09:30
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getsifangzhengcekuAction()
    {
        ini_set("max_execution_time", 36000);
        $sifangApi = "http://www.cdsme.com";
        $zhengcekuM = new zhengcekuModule();
        $page = $this->common->Get("page") == "" ? 1 : $this->common->Get("page");
        $getJsonStr = $this->common->get_webHtml("{$sifangApi}/xcxapi.aspx?type=getzhengceku&page={$page}");
        $getJson = json_decode($getJsonStr, true);
        $iswhile = true;
        while ($iswhile) {
            var_dump("{$sifangApi}/xcxapi.aspx?type=getzhengceku&page={$page}");
            flush();
            if (count($getJson) > 0) {
                $page = $page + 1;
                $iswhile = true;
            } else {
                $iswhile = false;
                break;
            }
            foreach ($getJson as $k => $v) {
                $zhengcekuM->insertFromSifangdata($v);
            }
            $getJsonStr = $this->common->get_webHtml("{$sifangApi}/xcxapi.aspx?type=getzhengceku&page={$page}");
            $getJson = json_decode($getJsonStr, true);
        }
        $zhengcekuM->TreatmentSifangshujuByids();
        returnSuccess("导入完成");
    }

    /**
     * 向四方平台插入数据
     * @date: 2019年9月3日 下午3:17:47
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function inserttosifangAction()
    {
        $t = $this->common->Get("t");
        $ids = $_GET["ids"];
        //四方数据库表
        $sifang_t = "article";
        if ($t == "zhengcedongtai") {
            $classid = 84;
        } else if ($t == "zhengcejiedu") {
            $classid = 77;
        } else if ($t == "zhengceku") {
            $sifang_t = "zhengce";
            $classid = '';
        } else {
            returnFail("暂无该表的接口");
        }

        $tableM = new Model($t);
        $zhengcekuM = new zhengcekuModule();
        $dataList = $tableM->where("id in ({$ids})")->all();
        foreach ($dataList as $k => $v) {
            //发送请求
            $data = $v;
            //数据转换
            if ($t == "zhengcedongtai") {
                $data["biaoti"] = $data["biaoti"];
                $data["suoluetu"] = str_replace("/public/webuploader/", $this->common->getHostDomain() . "/public/webuploader/", $data["fengmian"]);
                $data["biaoqian"] = str_replace(",", " ", $data["biaoqian"]);
                $data["guanjianci"] = $data["biaoqian"];
                $data["neirong"] = htmlspecialchars_decode($data["neirong"]);
                $data["neirong"] = str_replace("/public/upload/", $this->common->getHostDomain() . "/public/upload/", $data["neirong"]);

                $data["shenhe"] = "未审核";
                $data["classid"] = $classid;
            } else if ($t == "zhengcejiedu") {
                $data["miaoshu"] = $data["description"];
                //替换内容图片和文件路径 neirong
                $data["neirong"] = str_replace("/public/upload/", $this->common->getHostDomain() . "/public/upload/", $data["content"]);
                $data["neirong"] = htmlspecialchars_decode($data["neirong"]);
                $data["neirong"] = str_replace("/public/upload/", $this->common->getHostDomain() . "/public/upload/", $data["neirong"]);
                $data["paixu"] = $data["paixu"];
                $data["biaoqian"] = str_replace(",", " ", $data["biaoqian"]);
                $data["guanjianci"] = $data["biaoqian"];
                $data["shenhe"] = "未审核";
                $data["classid"] = $classid;

            } else if ($t == "zhengceku") {
                //returnFail("政策库接口开发中");
                $classid = '';
                $data = $zhengcekuM->getzhengcekuMokuaihuaDetail($v["id"]);
                $data["neirong"] = str_replace("/public/upload/", $this->common->getHostDomain() . "/public/upload/", $data["content"]);
                $data["u3"] = $data["bumen"];
                $data["fawenshijian"] = $data["fawenriqi"];
                $data["diqu"] = $data["jibie"];

                $data["neirong"] = htmlspecialchars_decode($data["content"]);
                $data["neirong"] = str_replace("/public/upload/", $this->common->getHostDomain() . "/public/upload/", $data["neirong"]);

                $data["zhaiyao"] = htmlspecialchars_decode($data["hexinneirong"]);
                $data["shenbaoduixiang"] = htmlspecialchars_decode($data["fuchitiaojian"]);
                $data["shenbaocailiao"] = htmlspecialchars_decode($data["shenbaocailiao"]);
                $data["shenbaoliucheng"] = htmlspecialchars_decode($data["liuchengshenbao"]);
                $data["lianxifangshi"] = htmlspecialchars_decode($data["lianxifangshi"]);

                $data["shenhe"] = "未审核";
                //资金扶持
                if ($v["sort_id"] == 4) {
                    //申报指南
                    preg_match_all('/指南/', $v["biaoti"], $res);

                    if (isset($res[0][0])) {
                        // var_dump($res);
                        $classid = '175';
                        $data["classid"] = $classid;
                    }

                    //公示公告
                    preg_match_all('/公告/', $v["biaoti"], $res);

                    if (isset($res[0][0])) {
                        // var_dump($res);
                        $classid = '176';
                        $data["classid"] = $classid;
                    }
                    preg_match_all('/公示/', $v["biaoti"], $res);

                    if (isset($res[0][0])) {
                        // var_dump($res);
                        $classid = '176';
                        $data["classid"] = $classid;
                    }

                    //申报
                    if ($classid == "") {
                        $classid = '174';
                        $data["classid"] = $classid;
                    }

                }

                //资质资格
                if ($v["sort_id"] == 5) {
                    //申报指南
                    preg_match_all('/指南/', $v["biaoti"], $res);

                    if (isset($res[0][0])) {
                        // var_dump($res);
                        $classid = '178';
                        $data["classid"] = $classid;
                    }

                    //公示公告
                    preg_match_all('/公告/', $v["biaoti"], $res);

                    if (isset($res[0][0])) {
                        // var_dump($res);
                        $classid = '179';
                        $data["classid"] = $classid;
                    }
                    preg_match_all('/公示/', $v["biaoti"], $res);

                    if (isset($res[0][0])) {
                        // var_dump($res);
                        $classid = '179';
                        $data["classid"] = $classid;
                    }

                    //申报
                    if ($classid == "") {
                        $classid = '177';
                        $data["classid"] = $classid;
                    }

                }

                //政策文件
                if ($v["sort_id"] == 6) {
                    preg_match_all('/通知/', $v["biaoti"], $res);
                    $classid = '173';
                    $data["classid"] = $classid;
                }
            }
            $this->send_post("http://www.cdsme.com/xcxapi.aspx?type=addfromxcx&t={$sifang_t}", $data);
        }
        $re_data["msg"] = "已提交到四方平台，请登录四方平台查看";
        $re_data["status"] = true;
        returnResponse($re_data);
    }

    /**
     * 发送post请求
     * @param string $url 请求地址
     * @param array $post_data post键值对数据
     * @return string
     */
    function send_post($url, $post_data)
    {
        $postdata = http_build_query($post_data);
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type:application/x-www-form-urlencoded',
                'content' => $postdata,
                'timeout' => 15 * 60 // 超时时间（单位:s）
            )
        );
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        return $result;
    }

    /**
     * 是否启用小程序所有功能
     * Notes:
     * User: gonghuayao
     * Date: 2019-12-04
     * Time: 14:10
     */
    public function startappAction()
    {
        returnSuccess(true);
    }

}
